#include <jni.h>  
#include "Parallel.h"  
#include <stdio.h>  
#include <sys/io.h>

JNIEXPORT jchar JNICALL Java_br_com_jparallelport_parallel_ParallelPortLinux_inb_1wrapper
  (JNIEnv * end, jobject obj, jboolean epp)
{
	unsigned char read = 0x01;

	unsigned short ADD_PORT;
	unsigned short STATUS_PORT;
	
	if(epp){
		ADD_PORT 	= 0x37b;
		STATUS_PORT	= 0x37b;
	}else{
		ADD_PORT 	= 0x378;
		STATUS_PORT	= ADD_PORT + 1;
	}

	if (ioperm(ADD_PORT, 3, 1)) {
		printf("Couldn't get the port.\n");
		perror("ioperm problem:");
		return read;
	}
	
	read = inb(STATUS_PORT);
	return (jchar)read;
}


JNIEXPORT void JNICALL Java_br_com_jparallelport_parallel_ParallelPortLinux_outb_1wrapper
  (JNIEnv * env, jobject obj, jchar value)
{
	if (ioperm(0x378, 3, 1)) {
		printf("Couldn't get the port.\n");
		perror("ioperm problem:");
		return;
	}

	outb(value, 0x378);
}
